﻿using System;
using Medianamik.Core.Action;

namespace Medianamik.Core.Security
{
    public class UserProfileActionHandler : IActionHandler
    {
        public void Initialize(ActionManager events)
        {
            events.AfterChangeNodeInstanceActiveStatus += AfterChangeNodeInstanceActiveStatus;
        }

        void AfterChangeNodeInstanceActiveStatus(ActionEventArgs<NodeInstance> args)
        {
            if (args.Item.Node.TypeId == MedianamikTypes.MedianamikProfile)
            {
                DALProviderManager.DALProvider.SecurityDALProvider
                    .SetLockUser(args.Item[MedianamikProperties.ProfileUser].GetValue<Guid>(), 
                        !args.Item.IsActive);
            }

        }

        public string Description
        {
            get { return "Permet de synchroniser le champ actif sur le UserProfile et la table User"; }
        }
    }
}
